<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by JetBrains PhpStorm.
 * User: User
 * Date: 2/19/13
 * Time: 3:21 PM
 * To change this template use File | Settings | File Templates.
 */
class Article_model extends WST_Model {
    private $_table = "article";

    function __contruct(){
        parent::__construct();
    }
    public function getSingle($id){
        $this->db->where('id',$id);
        $query = $this->db->get($this->_table);
        $data=$query->row_array();
        $query->free_result();
        return $data;
    }
    public function count_all($param=array()){
        if(count($param)>0){
            $this->db->like('title',$param['keyword']);
            $this->db->or_like('alias',$param['keyword']);
        }
        return $this->db->count_all_results($this->_table);
    }
    public function find_all($page_size = 20, $current_page = 1,$param=array()){
        $where="";
        if(count($param)>0){
            $where.=" WHERE title LIKE '%".$param['keyword']."%' OR alias LIKE '%".$param['keyword']."%'  ";
        }
        $sql = "select * from ".$this->_table. $where."   order by id ASC";
        if ($current_page > 0 && $page_size > 0) {
            $offset = ($current_page-1)* $page_size;
            $sql .= " limit {$offset}, {$page_size}";
        }
        $query = $this->db->query($sql);
        $data = $query->result_array();
        $query->free_result();
        return $data;
    }
}
